import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./App";
import reportWebVitals from "./reportWebVitals";

const root = ReactDOM.createRoot(
  document.getElementById("root") as HTMLElement
);
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();

// 1
function removeElement(nums: number[], val: number): number {
  // 方式一
  // return nums.filter(num => num !== val).length
  // 方式二
  while (nums.includes(val)) {
    nums.splice(nums.indexOf(val), 1);
  }
  return nums.length;
}

// const len = removeElement([1, 2, 3, 4, 5], 3);
// console.log(len);

function search(nums: number[], target: number): number {
  return nums.indexOf(target)
}


function countConsistentStrings(allowed: string, words: string[]): number {
  // 解释：输入：allowed = "ab", words = ["ad","bd","aaab","baa","badab"]
  // 输出：2
  // 解释：字符串 "aaab" 和 "baa" 都是一致字符串，因为它们只包含字符 'a' 和 'b' 
  return words.reduce((p, n) => {
    return n.split('').every(str => allowed.includes(str)) ? ++p : p
  }, 0)
}

const s1 = countConsistentStrings("ab",["ad","bd","aaab","baa","badab"]) // 2
const s2 = countConsistentStrings("abcd",["ad","bd","aaab","baa","badab"]) // 5
const s3 = countConsistentStrings("abe",["ad","bd","aeaab","baa","baedab"]) // 2
const s4 = countConsistentStrings("abf",["add","bd","aaab","bafa","badab"]) // 2
const s5 = countConsistentStrings("abgf",["adg","bd","aaafb","baa","badab"]) // 2

console.log(s1, s2, s3, s4, s5)